<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<c:if test="${userID==null}">
  <c:redirect url="index.jsp" />
</c:if>

<c:if test="${userType!='A'}">
  <c:redirect url="main.jsp" />
</c:if>

<c:if test="${param.mode=='del'}">
  <sql:update dataSource="${dataSource}">
  delete from t_users where c_uid = ? 
  <sql:param value="${param.target}" />
  </sql:update>

  <h3>User deleted</h3>
</c:if>

<html>
  <head>
    <title><fmt:message key="editusers.title" bundle="${lang}"/></title>
  </head>

  <body link="#000000" vlink="#000000" alink="#000000">
    <p><fmt:message key="editusers.ins" bundle="${lang}"/></p>
    <sql:query var="users" dataSource="${dataSource}">
    select c_uid,c_type from t_users order by c_uid</sql:query>

    <table border="0" width="410">
      <tr>
        <td bgcolor="#0000FF" width="115">
          <b>
            <font color="#FFFFFF" size="4">
            <fmt:message key="word.action" bundle="${lang}"/></font>
          </b>
        </td>

        <td bgcolor="#0000FF" width="45">
          <b>
            <font color="#FFFFFF" size="4">
            <fmt:message key="word.user" bundle="${lang}"/></font>
          </b>
        </td>

        <td bgcolor="#0000FF" width="246">
          <b>
            <font color="#FFFFFF" size="4">
            <fmt:message key="word.type" bundle="${lang}"/></font>
          </b>
        </td>
      </tr>

      <c:forEach var="row" items="${users.rows}"
      varStatus="status">
        <c:url value="${pageContext.request.requestURI}" var="del">
          <c:param name="mode" value="del" />

          <c:param name="target" value="${row.c_uid}" />
        </c:url>

        <c:url value="edituser.jsp" var="edit">
          <c:param name="mode" value="edit" />

          <c:param name="target" value="${row.c_uid}" />
        </c:url>

        <jsp:useBean id="status"
        type="javax.servlet.jsp.jstl.core.LoopTagStatus" />

        <c-rt:choose>
          <c-rt:when test="<%=status.getCount()%2==0%>">
            <c:set var="color" value="#FFFFFF" />
          </c-rt:when>

          <c-rt:otherwise>
            <c:set var="color" value="#FFFF66" />
          </c-rt:otherwise>
        </c-rt:choose>

        <tr bgcolor="<c:out value="${color}"/>">
        <td width="115">
          <a href="<c:out value="${del}"/>">[
          <fmt:message key="word.delete" bundle="${lang}"/>]</a>

          <a href="<c:out value="${edit}"/>">[
          <fmt:message key="word.edit" bundle="${lang}"/>]</a>
        </td>

        <td width="35">
          <b>
            <c:out value="${row.c_uid}" />
          </b>
        </td>

        <td width="246">
          <c:choose>
            <c:when test="${row.c_type=='A'}"><fmt:message key="type.a" bundle="${lang}"/></c:when>

            <c:when test="${row.c_type=='R'}"><fmt:message key="type.r" bundle="${lang}"/></c:when>

            <c:when test="${row.c_type=='G'}"><fmt:message key="type.g" bundle="${lang}"/></c:when>

            <c:otherwise>
              <c:out value="${row.c_type}" />
            </c:otherwise>
          </c:choose>
        </td>
        </tr>
      </c:forEach>
    </table>

    <br />

    <a href="admin.jsp">[<fmt:message key="word.exit" bundle="${lang}"/>]</a>
  </body>
</html>

